const { get,post } = require("../../utils/request");
Page({
  data: {
    // 初始化列表数据
    items: []
  },

  onLoad: function(){
    get('/system/record/list?wxId='+wx.getStorageSync("openid"), {}).then(res => {
      debugger
      if (res.data.code === 200 && res.data.rows) {
        this.setData({
          items: res.data.rows
        });
      } else {
        wx.showToast({
          title: '暂无预约记录',
          icon: 'none'
        });
      }
    }).catch(err => {
      wx.showToast({
        title: '暂无预约记录',
        icon: 'none'
      });
    });
  },

  // 详情按钮点击事件
  onDetail: function(e) {
    const index = e.currentTarget.dataset.index;
    const item = this.data.items[index];
    debugger
    wx.navigateTo({
      url: '/pages/appointment-success/appointment-success?name='+item.name+'&storeName='+item.storeName+'&carName='+item.carName+'&phone='+item.phone+'&submitTime='+item.createTime
    });
  },

  // 删除按钮点击事件
  onDelete: function(e) {
    const index = e.currentTarget.dataset.index;
    const item = this.data.items[index];
    
    wx.showModal({
      title: '确认删除',
      content: `您确定要删除 "${item.name}" 吗？`,
      confirmText: '删除',
      confirmColor: '#f5222d',
      success: (res) => {
        if (res.confirm) {
          // 删除数据
          const newItems = [...this.data.items];
          newItems.splice(index, 1);
          this.setData({ items: newItems });
          
          wx.showToast({
            title: '删除成功',
            icon: 'none',
            duration: 1500
          });
        }
      }
    });
  }
});
